import pandas as pd
import os

def import_weather(source_dir):
    if not os.path.exists(source_dir):
        print("path %s not exist" % source_dir)
        return


    # data=pd.DataFrame(columns=['商品编码','日期','销售数量','销售额','最高气温','最低气温','天气','风向','风力'])
    # data=pd.DataFrame(columns=['日期','最高气温','最低气温','天气','风向','风力'])
    
    data_list=[]
    for curr_file in os.listdir(source_dir):
        # print('current file:',curr_file)
        if os.path.isfile(source_dir+'/'+curr_file) and os.path.splitext(curr_file)[1] == '.csv':
            # print('parse csv file ', curr_file)
            csv_file=  pd.read_csv(source_dir + '/' + curr_file)
            # print('csv data :\n',csv_file)
            # data.append(csv_file)
            data_list.append(csv_file)

    
    return pd.concat(data_list,ignore_index=True,sort=False)


if __name__ == "__main__":
    data=import_weather('/Users/yanjunhua/work/ygroup/project/shell-tools/weather/weather/data/')

    # df=pd.DataFrame(data[:,2:])
    # data= data.drop(['0'],axis=1)
    # data=data[:,2:]

    sorted_data=data.iloc[:,1:]
    print(sorted_data)
    sorted_data.to_csv("./weather.csv",index=False)